//
//  YZPigDocHealthCell.m
//  VET
//
//  Created by YZ on 2018/7/19.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZPigDocHealthCell.h"

@interface YZPigDocHealthCell ()

@property (nonatomic, strong) UILabel *medicineLb;

@property (nonatomic, strong) UILabel *dateLb;

@property (nonatomic, strong) UILabel *typeLb;

@property (nonatomic, strong) UILabel *healthTypeLb;

@property (nonatomic, strong) UIImageView *transferImgView;

@end

@implementation YZPigDocHealthCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.layer.masksToBounds = YES;
        [self.contentView addSubview:self.medicineLb];
        [self.contentView addSubview:self.dateLb];
        [self.contentView addSubview:self.typeLb];
        [self.contentView addSubview:self.healthTypeLb];
        [self.contentView addSubview:self.transferImgView];
        
        [self makeContraints];
    }
    return self;
}

- (void)makeContraints
{
    [self.medicineLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(kCurrentDeviceNum(20));
        make.top.mas_equalTo(kCurrentDeviceNum(10));
        make.width.mas_lessThanOrEqualTo(300);
    }];
    
    [self.typeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.medicineLb);
        make.top.equalTo(self.medicineLb.mas_bottom);
        make.width.mas_lessThanOrEqualTo(150);
    }];
    
    [self.healthTypeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.typeLb.mas_right);
        make.top.equalTo(self.typeLb);
        make.width.mas_lessThanOrEqualTo(150);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-kCurrentDeviceNum(10));
    }];
    
    [self.transferImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(kCurrentDeviceNum(7), kCurrentDeviceNum(12)));
        make.right.equalTo(self.contentView.mas_right).offset(-kCurrentDeviceNum(20));
    }];
    
    [self.dateLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.equalTo(self.transferImgView.mas_left).offset(-kCurrentDeviceNum(10));
        make.width.mas_lessThanOrEqualTo(150);
    }];
    
}
#pragma mark -- setters && getters

- (UILabel *)medicineLb
{
    if (!_medicineLb) {
        _medicineLb =  [UILabel new];
        _medicineLb.textAlignment = NSTextAlignmentLeft;
        _medicineLb.font = kCurrentDeviceFont(16);
        _medicineLb.textColor = kColorWithHex(0x434343);
    }
    return _medicineLb;
}

- (UILabel *)dateLb
{
    if (!_dateLb) {
        _dateLb =  [UILabel new];
        _dateLb.textAlignment = NSTextAlignmentRight;
        _dateLb.font = kCurrentDeviceFont(12);
        _dateLb.textColor = kColorWithHex(0x9B9B9B);
    }
    return _dateLb;
}

- (UILabel *)typeLb
{
    if (!_typeLb) {
        _typeLb =  [UILabel new];
        _typeLb.textAlignment = NSTextAlignmentLeft;
        _typeLb.font = kCurrentDeviceFont(14);
        _typeLb.textColor = kColorWithHex(0x9B9B9B);
        _typeLb.text = @"保健类型:";
    }
    return _typeLb;
}

- (UILabel *)healthTypeLb
{
    if (!_healthTypeLb) {
        _healthTypeLb =  [UILabel new];
        _healthTypeLb.textAlignment = NSTextAlignmentLeft;
        _healthTypeLb.font = kCurrentDeviceFont(14);
        _healthTypeLb.textColor = kColorWithHex(0x9B9B9B);
    }
    return _healthTypeLb;
}

- (UIImageView *)transferImgView
{
    if (!_transferImgView) {
        _transferImgView = [UIImageView new];
        _transferImgView.image = [UIImage imageNamed:@"ico_right"];
    }
    return _transferImgView;
}

- (void)setModel:(YZPigDocHealthModel *)model
{
    _model = model;
    NSString *str = nil;
    NSInteger count = model.medicine.count;
    if (count == 0) {
        str = @"";
    }else if (count == 1) {
        str = model.medicine.firstObject.itemValue;
    }else if (count == 2)
    {
        str = [NSString stringWithFormat:@"%@、%@",model.medicine.firstObject.itemValue,model.medicine.lastObject.itemValue];
    }else
    {
        str = [NSString stringWithFormat:@"%@等%ld种药物",model.medicine.firstObject.itemValue,count];
    }
    self.medicineLb.text = str;
    self.dateLb.text = model.careTime;
    self.healthTypeLb.text = model.careType.itemValue;
}

@end
